import { AppModel } from '../../../../model/AppModel'


export default {

    category: Blockly.Categories.control ,
    
    color: [
        Blockly.Colours.event.primary,
        Blockly.Colours.event.secondary,
        Blockly.Colours.event.tertiary
    ] ,

    previousStatement: true ,
    nextStatement: true ,

    init() {
        this.appendDummyInput()
                .appendField('连接到WiFi')
        this.appendValueInput("ssid")
        this.appendValueInput("password")
            .appendField("密码:")
    } ,

    coder: {
        JavaScript(block: any, coder: any) {
            let ssid = coder.valueToCode(block,'ssid', coder.ORDER_NONE) || '""'
            let password = coder.valueToCode(block,'password', coder.ORDER_NONE) || '""'
            if(!password.match(/^["'`]/)){
                password = `"${password}"`
            }
            return `${coder.indentString()}beapi.wifi.connect(${ssid},${password})\n`
        }
    }
}
